import axios from 'axios';
import store from '../store/store'
// const baseURL = 'http://192.168.0.1:8080/'
const baseURL = '/api/'


const request = axios.create({
    baseURL: baseURL, // 设置跨域代理接口统一的前置地址
    // timeout: 10000,
    headers: {
        "Content-Type": "application/json; charset=utf-8",
        // 'Authorization': sessionStorage.getItem("access_token")
    },
    timeout: 5000


});

// const service = axios.create({
//     // process.env.NODE_ENV === 'development' 来判断是否开发环境
//     // easy-mock服务挂了，暂时不使用了
//     // baseURL: 'https://www.easy-mock.com/mock/592501a391470c0ac1fab128',
// });
// 添加请求拦截器
request.interceptors.request.use(
    config => {
        // 在发送请求之前做些什么

        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);
// 添加响应拦截器
request.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            console.log('23333');

            Promise.reject();
        }
    },
    error => {
        console.log(error.response.data);
        store.commit("modalFlag", true)
        store.commit("modalData", {code: error.response.data.code, msg: error.response.data.msg})
        return Promise.reject();
    }
);


const get = (url, data) => request.get(url, {params: data});
const post = (url, data) => request.post(url, data);

export {
    get, post
};
// export default request;
